set more off
clear all

global IPDIR Dropbox\INE\data\matchip

cap log close
log using an_match,t replace

*********************************************************************************
*** Program to make Table B-1, analysis of our patent and TM match
*********************************************************************************

*** Trademarks
use enia_inno_ip_ex, clear
keep if totrev~=. & year>1994
keep id year napp_tm
drop if napp==0
duplicates drop
save temp, replace

insheet using "$IPDIR\tm_ine_applnREV2.csv", clear 
rename year_a year
rename id_b id
drop if tm_appln_c==0 | tm_appln_c==.
merge m:1 id year using temp
*scatter tm_appln_c napp if _m==3

keep if year<2006 & year>1994
collapse (sum) tm_appln_c napp,by(year)
gen pct_matched = nap/tm_a*100
list, clean noobs

insheet using "$IPDIR\tm_ine_applnREV2.csv", clear 
rename year_a year
rename id_b id
drop if tm_appln_c==0 | tm_appln_c==.
merge m:1 id year using temp

keep if year<2006 & year>1994
keep id _m year
gen n_applicants = 1
gen n_matched = 1 if _m==3
collapse (sum) n_app n_match,by(year)
gen pct_matched = n_matched/n_applicants*100
list, clean noobs


*** Patents
use enia_inno_ip_ex, clear
keep if totrev~=. & year>1994
keep id year napp_pat
drop if napp==0
duplicates drop
save temp, replace

import excel using "$IPDIR\pat_appln.xlsx", clear first
rename year_a year
rename idb id 
drop if p_appln_c==0 | p_appln_c==.
merge m:1 id year using temp
*scatter p_appln_c napp if _m==3

keep if year<2006 & year>1994
collapse (sum) p_appln_c napp,by(year)
gen pct_matched = nap/p_a*100
list, clean noobs

import excel using "$IPDIR\pat_appln.xlsx", clear first
rename year_a year
rename idb id
drop if p_appln_c==0 | p_appln_c==.
merge m:1 id year using temp

keep if year<2006 & year>1994
keep id _m year
gen n_applicants = 1
gen n_matched = 1 if _m==3
collapse (sum) n_app n_match,by(year)
gen pct_matched = n_matched/n_applicants*100
list, clean noobs

log close
